#!perl
# Copyright (C) 2001-2008, The Parrot Foundation.

use Getopt::Long;
use strict;
use warnings;
use lib qw( lib );

my %opts;
GetOptions(
    'archive=s' => \$opts{archive},
    'parrot_revision=s' => \$opts{parrot_revision},
);

# need runtests from T::H, but avoid running all our parrot invocations with -w
use Test::Harness ();
undef $Test::Harness::Switches;

my @tests = map { glob($_) } qw{t/*.t t/internals/*.t};

my $tap_harness_class = 'TAP::Harness';
$tap_harness_class .= '::Archive' if $opts{archive};

my $extra_properties;
$extra_properties->{'Parrot Revision'} = $opts{parrot_revision}
  if $opts{parrot_revision};
$extra_properties->{'Submitter'} = $ENV{SMOLDER_SUBMITTER}
  if $ENV{SMOLDER_SUBMITTER};

my $harness;
eval "require $tap_harness_class;";
if ($@) {
    Test::Harness::runtests(@tests);
    exit;
}
else {
    $harness = $tap_harness_class->new({
        verbosity => $ENV{HARNESS_VERBOSE},
        merge     => 1,
        jobs      => $ENV{TEST_JOBS} || 1,
        directives => 1,
        $opts{archive} ? ( archive => $opts{archive} ) : (),
        $extra_properties ? ( extra_properties => $extra_properties ) : (),
    });
}
my $results = $harness->runtests(@tests);

# a non-zero code stops make after test failures (RT #60116)
exit ( $results->all_passed() ? 0 : 1 );

=head1 NAME

t/harness - partcl Test Harness

=head1 NOTES

Borrowed from parrot's t/harness to get TEST_JOBS working.

=cut
